package com.lxl.hadoop.reverse;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @Author lixilin
 * @Date 2022/1/9 12:20
 * @Description
 */
public class WcReduce2 extends Reducer<Text, Text,Text, NullWritable> {
    Text outKey = new Text();
    NullWritable outVal = NullWritable.get();
    StringBuilder kb = new StringBuilder();
    @Override
    protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
        // at    a.txt-->2
        kb.setLength(0);
        kb.append(key.toString());
        kb.append("\t");
        for (Text value : values) {
            kb.append(value.toString());
            kb.append("\t");
        }
        outKey.set(kb.substring(0,kb.length()-1));
        context.write(outKey,outVal);

    }
}
